import lua.IMessageFormat;
import lua.IUserCredential;
import lua.MessageFormatImpl;
import lua.UserCredentialImpl;

import java.util.UUID;
import java.util.function.*;

/**
 * @author deity
 * @version 1.0
 * @date 2020/11/7 13:57
 * <p>
 * 需求改动:
 * 所有的用户验证，可以同时获取用户的验证信息[是否认证成功 |成功-返回用户|null]
 */
public class LambdaMethod {
    public static void main(String[] args) {
        // 1-默认方法
        IUserCredential ic = new UserCredentialImpl();
        System.out.println(ic.verifyUser("admin") + " ------1----- " + ic.getCredential("admin"));

        //2-静态方法
        if (IMessageFormat.verifyMessage("Hello world")) {
            IMessageFormat format = new MessageFormatImpl();
            System.out.println(format.format("Hello", "json"));
        }

        //3-匿名内部类，实现接口的抽象方法
        IUserCredential ic2 = new IUserCredential() {
            @Override
            public String verifyUser(String userName) {
                return "admin".equals(userName) ? "管理员" : "会员";
            }
        };
        System.out.println(ic2.verifyUser("admin") + "---3----" + ic2.verifyUser("manager"));

        //4-Lambda表达式
        IUserCredential ic3 = (userName) -> "admin".equals(userName) ? "Lambda管理员" : "Lambda会员";
        System.out.println(ic3.verifyUser("admin"));

        // 5-传入一个对象,返回一个boolean
        Predicate<String> pre = (userName) -> "admin".equals(userName);
        System.out.println(pre.test("admin") + "----5----" + pre.test("manager"));

        // 6-传入一个对象,不返回结果
        Consumer<String> con = (message) -> System.out.println("----6----要发送的消息:" + message + "消息发送成功");
        con.accept("Hello Lua");

        // 7-传入对象T,返回对象R
        Function<String, Integer> fun = (gender) -> "male".equals(gender) ? 1 : 0;
        System.out.println(fun.apply("male") + "----7---" + fun.apply("female"));

        // 8-返回T对象的创建工厂
        Supplier<String> sup = () -> UUID.randomUUID().toString();
        System.out.println(sup.get() + "----8----" + sup.get() + "---" + sup.get());

        // 9-接收参数对象T,返回T对象
        UnaryOperator<String> uo = (img) -> img += "[100x200]";
        System.out.println(uo.apply("原图--"));

        // 10-接收2个T对象,返回一个T对象
        BinaryOperator<Integer> bo = (i2, i3) -> i2 > i3 ? i2 : i3;
        System.out.println(bo.apply(13, 14));


    }
}
